<template>
  <div style=" width :50%;margin: auto;">
    

    <el-form ref="form" :rules="rules" :model="form" label-width="100px" >
  <el-form-item label="OA流水号" prop="oaid">
    <el-input v-model="form.oaid"></el-input>
  </el-form-item>
  <el-form-item label="原内容" prop="content">
    <el-input v-model="form.content"></el-input>
  </el-form-item>
  <el-form-item label="修改内容" prop="recontent">
    <el-input v-model="form.recontent"></el-input>
  </el-form-item>
  <el-form-item label="修改时间" prop="date1">
    <el-col :span="11">
      <el-date-picker type="date" placeholder="选择日期" v-model="form.date1" style="width: 100%;"></el-date-picker>
    </el-col>
    
    <el-col class="line" :span="2">-</el-col>
    <el-col :span="11" >
      <el-form-item prop="date2">
      <el-time-picker placeholder="选择时间" v-model="form.date2" style="width: 100%;"></el-time-picker>
    </el-form-item>
    </el-col>
  </el-form-item>

  <el-form-item label="备注" prop="note">
    <el-input type="textarea" :autosize="{minRows:4}" v-model="form.note"></el-input>
  </el-form-item>
  <el-form-item label="修改人" prop="name">
    <el-input v-model="form.name"></el-input>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="onSubmit('form')">立即创建</el-button>
    <el-button @click="resetForm('form')">重置</el-button>
   
  </el-form-item>
</el-form>

  </div>

</template>

<script>
  export default {
    data() {
      return {
        form: {
          name: '',
          oaid: '',
          date1: '',
          date2: '',
          content: '',
          recontent: '',
          note: ''
        },
     
    rules: {
          name: [
            { required: true, message: '请输入修改人名称', trigger: 'blur' }
          ],
          oaid: [
            { required: true, message: '请输入OA流水号', trigger: 'blur' }
          ],
          date1: [
            { type: 'date', required: true, message: '请选择日期', trigger: 'change' }
          ],
          date2: [
            { type: 'date', required: true, message: '请选择时间', trigger: 'change' }
          ],
          content: [
            { required: true, message: '请输入原内容', trigger: 'blur' }
          ],
          recontent: [
            { required: true, message: '请输入修改内容', trigger: 'blur' }
          ],
          note: [
            { required: true, message: '请填写备注', trigger: 'blur' }
          ]
        },
      }
    },
    methods: {
      onSubmit(form) {
        this.$refs[form].validate((valid) => {
          if (valid) {
            this.$axios({
          url: "/record/add",
          method: "post",
          data: {
            name: this.form.name,
            oaid: this.form.oaid,
            date1: this.form.date1,
            date2: this.form.date2,
            content: this.form.content,
            recontent: this.form.recontent,
            note: this.form.note,
          },
        })
          .then((res) => {
             if(res.data.flag==true){
              alert(res.data.message);
              this.$refs[form].resetFields();
             }else{
              alert("添加失败")
             }
          })
          .catch((err) => {
            alert("添加失败")
            console.log(err);
          });
          } else {
            console.log('error submit!!');
            return false;
          }
        });

      },
      resetForm(form) {
        this.$refs[form].resetFields();
      }
    }
  }
</script>
